<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__ADMIN__css/font.css">
    <link rel="stylesheet" href="__ADMIN__css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>

    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">

<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">

            <input type="text" name="name"  placeholder="请输入应用名称" autocomplete="off" class="layui-input">
            <button class="layui-btn" type="button"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>

            <button class="layui-btn layui-btn-danger fr" id="del" type="button"><i class="layui-icon ">&#xe640;</i>批量删除</button>
            <button class="layui-btn layui-btn-warm  fr" id="refresh" type="button"><i class="layui-icon ">&#xe63f;</i>刷新</button>
            <button class="layui-btn layui-btn-normal fr" id="recoveryall" type="button"><i class="layui-icon ">&#xe654;</i>批量恢复</button>

        </form>
    </div>

    <table class="" lay-filter="test" id="table">

    </table>


</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="recovery">恢复</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    //修改页面接口
    var upurl = '/admin/application/edit/id/';
    //删除接口
    var delurl = '/admin/application/recycledDelApplication';

    var recovery_url = '/admin/application/recoveryApplication';
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#table'
            ,method:'post'
            ,height: 'full-200'
            ,url: '/admin/application/recycled' //数据接口
            ,page: true //开启分页
            ,id:'idTest'
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
                ,{type: 'checkbox'}
                ,{field: 'name', title: '应用名称', width:200}
                ,{field: 'introduce', title: '应用介绍',width:700}
                ,{field: 'view_num', title: '应用浏览量', width:100}
                ,{field: 'create_time', title: '创建时间', width:200}
                ,{fixed: 'right',title: '操作',width:150, align:'center', toolbar: '#barDemo'}
            ]]
        });

        table.on('tool(test)', function(obj){
            var data = obj.data;
            //监听删除
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: delurl,
                        data: {'id':data.id},
                        success: function (res) {
                            var success = JSON.parse(res);
                            if(success.code===200){
                                layer.msg(success.msg);
                                obj.del();
                                layer.close(index);
                            }else {
                                layer.msg(success.msg)
                            }

                        }
                    });

                });
            }
            //监听恢复
            if(obj.event === 'recovery'){
                layer.confirm('真的恢复行么', function(index){
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: recovery_url,
                        data: {'id':data.id},
                        success: function (res) {
                            var success = JSON.parse(res);
                            if(success.code===200){
                                layer.msg(success.msg);
                                obj.del();
                                layer.close(index);
                            }else {
                                layer.msg(success.msg)
                            }

                        }
                    });

                });
            }
        });
        });

        //批量删除
        $('#del').click(function () {
            var checkStatus = table.checkStatus('idTest');
            if(checkStatus.data.length===0){
                layer.msg("请选择要删除的行");
                return false;
            }
            layer.confirm('真的删除行么', function(index){
                var data1 = checkStatus.data;
                var data2 = [];
                for (var i=0;i<data1.length;i++)
                {
                    data2[i] = data1[i].id;
                }
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: '/admin/Application/recycledDelAllApplication',
                    data: {data:data2},
                    success: function (res) {
                        var success = JSON.parse(res);
                        if(success.code==200){
                            layer.msg(success.msg);
                            table.reload('idTest', {
                                url: '/admin/Application/recycled'
                                ,where: {'name':0}  //设定异步数据接口的额外参数
                                //,height: 300
                            });
                        }else {
                            layer.msg(success.msg)
                        }

                    }
                });
            });
        });

        $('#recoveryall').click(function () {
        var checkStatus = table.checkStatus('idTest');
        if(checkStatus.data.length===0){
            layer.msg("请选择要恢复的行");
            return false;
        }
        layer.confirm('真的删除行么', function(index){
            var data1 = checkStatus.data;
            var data2 = [];
            for (var i=0;i<data1.length;i++)
            {
                data2[i] = data1[i].id;
            }
            $.ajax({
                type: "POST",
                dataType: "json",
                url: '/admin/application/recoveryallApplication',
                data: {data:data2},
                success: function (res) {
                    var success = JSON.parse(res);
                    if(success.code==200){
                        layer.msg(success.msg);
                        table.reload('idTest', {
                            url: '/admin/Application/recycled'
                            ,where: {'name':0}  //设定异步数据接口的额外参数
                            //,height: 300
                        });
                    }else {
                        layer.msg(success.msg)
                    }

                }
            });
        });
    });

        //监听搜索提交
        var form = layui.form,layer = layui.layer;
        //刷新表格
        $('#refresh').click(function () {
            table.reload('idTest', {
                url: '/admin/Application/recycled'
                ,where: {'name':0,'type':0} //设定异步数据接口的额外参数
                //,height: 300
            });
        });
        form.on('submit(sreach)', function(data){
            table.reload('idTest', {
                url: '/admin/Application/recycled'
                ,where: data.field //设定异步数据接口的额外参数
                //,height: 300
            });
        });




</script>
<script>

</script>
</body>

</html>